package com.ruoyi.bbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bbs.domain.BbsModerator;
import com.ruoyi.bbs.service.IBbsModeratorService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 版主管理Controller
 * 
 * @author saruri
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/moderator")
public class BbsModeratorController extends BaseController
{
    @Autowired
    private IBbsModeratorService bbsModeratorService;

    /**
     * 查询版主管理列表
     */
    @RequiresPermissions("bbs:moderator:list")
    @GetMapping("/list")
    public TableDataInfo list(BbsModerator bbsModerator)
    {
        startPage();
        List<BbsModerator> list = bbsModeratorService.selectBbsModeratorList(bbsModerator);
        return getDataTable(list);
    }

    /**
     * 导出版主管理列表
     */
    @RequiresPermissions("bbs:moderator:export")
    @Log(title = "版主管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BbsModerator bbsModerator)
    {
        List<BbsModerator> list = bbsModeratorService.selectBbsModeratorList(bbsModerator);
        ExcelUtil<BbsModerator> util = new ExcelUtil<BbsModerator>(BbsModerator.class);
        util.exportExcel(response, list, "版主管理数据");
    }

    /**
     * 获取版主管理详细信息
     */
    @RequiresPermissions("bbs:moderator:query")
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") Long fid)
    {
        return success(bbsModeratorService.selectBbsModeratorByFid(fid));
    }

    /**
     * 新增版主管理
     */
    @RequiresPermissions("bbs:moderator:add")
    @Log(title = "版主管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BbsModerator bbsModerator)
    {
        return toAjax(bbsModeratorService.insertBbsModerator(bbsModerator));
    }

    /**
     * 修改版主管理
     */
    @RequiresPermissions("bbs:moderator:edit")
    @Log(title = "版主管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BbsModerator bbsModerator)
    {
        return toAjax(bbsModeratorService.updateBbsModerator(bbsModerator));
    }

    /**
     * 删除版主管理
     */
    @RequiresPermissions("bbs:moderator:remove")
    @Log(title = "版主管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable Long[] fids)
    {
        return toAjax(bbsModeratorService.deleteBbsModeratorByFids(fids));
    }
}
